local wezterm = require("wezterm")
local config = wezterm.config_builder()
config.automatically_reload_config = true

-- config.color_scheme = "Nord (Gogh)"

config.color_scheme = "tokyonight_moon"

-- 设置字体和窗口大小
config.font = wezterm.font("JetBrainsMono Nerd Font Mono")
config.font_size = 12.5
config.audible_bell = "Disabled"
config.default_cursor_style = "BlinkingBlock"
config.window_close_confirmation = "NeverPrompt"
config.window_decorations = "RESIZE"
config.enable_tab_bar = false
config.window_background_opacity = 0.92
config.initial_cols = 140
config.initial_rows = 38
config.window_padding = {
	left = 3,
	right = 3,
	top = 0,
	bottom = 0,
}

config.background = {
	-- {
	--
	-- 	source = {
	-- 		File = "/home/loong/Pictures/Screenshots/bg1.png",
	-- 	},
	-- 	hsb = {
	-- 		hue = 1.0,
	-- 		saturation = 1.02,
	-- 		brightness = 0.25,
	-- 	},
	-- 	width = "100%",
	-- 	height = "100%",
	-- },
	{
		source = {
			Color = "#282c35",
		},
		width = "100%",
		height = "100%",
		opacity = 0.72,
	},
}

-- 键盘绑定
local act = wezterm.action

config.leader = { key = ";", mods = "CTRL", timeout_milliseconds = 1000 }
config.keys = {
	{ key = "q", mods = "LEADER", action = act.QuitApplication },

	{ key = "h", mods = "LEADER", action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
	{ key = "v", mods = "LEADER", action = act.SplitVertical({ domain = "CurrentPaneDomain" }) },
	{ key = "c", mods = "LEADER", action = act.CloseCurrentPane({ confirm = false }) },

	{ key = "h", mods = "CTRL|SHIFT", action = act.ActivatePaneDirection("Left") },
	{ key = "l", mods = "CTRL|SHIFT", action = act.ActivatePaneDirection("Right") },
	{ key = "k", mods = "CTRL|SHIFT", action = act.ActivatePaneDirection("Up") },
	{ key = "j", mods = "CTRL|SHIFT", action = act.ActivatePaneDirection("Down") },

	-- CTRL + T 创建默认的Tab
	-- { key = "t", mods = "CTRL", action = act.SpawnTab("DefaultDomain") },
	-- CTRL + W 关闭当前Tab
	-- { key = "w", mods = "CTRL", action = act.CloseCurrentTab({ confirm = false }) },

	-- CTRL + SHIFT + 1 创建新Tab - WSL
	{
		key = "!",
		mods = "CTRL|SHIFT",
		action = act.SpawnCommandInNewTab({
			domain = "DefaultDomain",
			args = { "wsl", "-d", "Ubuntu-20.04" },
		}),
	},
}

for i = 1, 8 do
	-- CTRL + number to activate that tab
	table.insert(config.keys, {
		key = tostring(i),
		mods = "CTRL",
		action = act.ActivateTab(i - 1),
	})
end

-- 鼠标绑定
config.mouse_bindings = {
	-- copy the selection
	{
		event = { Up = { streak = 1, button = "Left" } },
		mods = "NONE",
		action = act.CompleteSelection("ClipboardAndPrimarySelection"),
	},

	-- Open HyperLink
	{
		event = { Up = { streak = 1, button = "Left" } },
		mods = "CTRL",
		action = act.OpenLinkAtMouseCursor,
	},
}

return config
